﻿using System;
using Microsoft.Practices.Prism.Regions;
using Infrastucture;
using Infrastucture.Controllers;
using Infrastucture.Navigation;
using TimeSplicerModule.Controllers;

namespace NavigationModule.Controllers
{

    public class LeftSideNavigationController : Controller
    {
        private readonly ITeamController _teamController;
        private readonly IStatusController _statusController;



        //public LeftSideNavigationController(ITeamController teamController, IStatusController statusController)
        //    :base()
        //{
        //    _teamController = teamController;
        //    _statusController = statusController;
        //}

        public void Navigate(NavigationLink link)
        {
            if (link.Display == "Settings")
            {
                ClearView(RegionNames.MainRegion);
                Uri uri = new Uri(typeof(Views.LeftSideNavigationView).Name, UriKind.Relative);
                this.RegionManager.RequestNavigate(RegionNames.LeftSideRegion, uri);
            }
            else if (link.Display == "Projects")
            {
                ClearView(RegionNames.LeftSideRegion);
                //Uri uri = new Uri(typeof(Views))
                var c = new TimeSplicerModule.Controllers.ProjectController();
                c.NavigateToListView();
            }
            else if (link.Display == "Tasks")
            {
                ClearView(RegionNames.MainRegion);
                var c = new TimeSplicerModule.Controllers.TaskController();
                c.NavigateToListView();
                // TODO:
                //throw new NotImplementedException();
            }
            else if (link.Display == "Dashboard")
            {

            }
            else if (link.Display == "Reports")
            {
                ClearView(RegionNames.MainRegion);
                var c = new DashboardModule.Controllers.TempReportsViewController();
                c.NavigateToView();
            }
            else if (link.Display == "Hub")
            {
                ClearView(RegionNames.LeftSideRegion);
                var c = new HubModule.Controllers.HubController();
                c.NavigateToView();
            }
        }
        public void NavigateFrom(NavigationLink link)
        {
            // need controller for time splicer
            if (link.Display == "Statuses")
            {
                //_statusController.NavigateToListView();
                var c = new TimeSplicerModule.Controllers.StatusController();
                c.NavigateToListView();
            }
            else if (link.Display == "Categories")
            {
                var c = new TimeSplicerModule.Controllers.CategoryController();
                c.NavigateToListView();
            }
            else if (link.Display == "Teams")
            {
                var c = new TimeSplicerModule.Controllers.TeamController();
                c.NavigateToListView();
            }
            else if (link.Display == "Application Roles")
            {
                var c = new TimeSplicerModule.Controllers.ApplicationRoleController();
                c.NavigateToListView();
            }
            else if (link.Display == "Job Roles")
            {
                var c = new TimeSplicerModule.Controllers.JobRoleController();
                c.NavigateToListView();
            }
            else if (link.Display == "Users")
            {
                var c = new TimeSplicerModule.Controllers.UserController();
                c.NavigateToListView();
            }
            else if (link.Display == "Project Roles")
            {
                var c = new TimeSplicerModule.Controllers.ProjectRoleController();
                c.NavigateToListView();
            }
            else if (link.Display == "Priorities")
            {
                var c = new TimeSplicerModule.Controllers.PriorityController();
                c.NavigateToListView();
            }
            else if (link.Display == "Services")
            {
                // TODO: create services controller
                var c = new TimeSplicerModule.Controllers.ServicesController();
                c.NavigateToView();
            }
        }
        public void ClearView(string region)
        {
            // need to cycle thro the region and remove all views
            var r = this.RegionManager.Regions[region];
            var views = r.Views;

            foreach (var v in views)
                r.Remove(v);
        }
    }
}
